package com.jeecms.wicool.dao.car.impl;


import java.util.List;

import org.springframework.stereotype.Repository;
import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.car.CarOrderConfDetailDao;
import com.jeecms.wicool.entity.car.CarOrderConfDetail;

@Repository
public class CarOrderConfDetailDaoImpl extends HibernateBaseDao<CarOrderConfDetail, Integer>
		implements CarOrderConfDetailDao {

	@Override
	protected Class<CarOrderConfDetail> getEntityClass() {
		// TODO Auto-generated method stub
		return CarOrderConfDetail.class;
	}
	@Override
	public Pagination getPage(Integer carOrderConfId,
			int pageNo, int pageSize) {
			Finder f = Finder.create("select bean from CarOrderConfDetail bean where 1=1 ");
			
			if (null!=carOrderConfId){
				f.append(" and bean.carOrderConf.id = :carOrderConfId");
				f.setParam("carOrderConfId",carOrderConfId);
			}
			f.append(" order by bean.id desc");
			return find(f, pageNo, pageSize);
	}
	@Override
	public CarOrderConfDetail findById(Integer id) {
		CarOrderConfDetail entity = get(id);
		return entity;
	}
	@Override
	public CarOrderConfDetail save(CarOrderConfDetail bean) {
		getSession().save(bean);
		return bean;
	}
	@Override
	public CarOrderConfDetail deleteById(Integer id) {
		CarOrderConfDetail entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	@Override
	public CarOrderConfDetail getByCarOrderConfId(Integer carOrderConfId) {
		Finder f = Finder.create("select bean from CarOrderConfDetail bean where 1=1 ");
		
		if (null!=carOrderConfId){
			f.append(" and bean.carOrderConf.id = :carOrderConfId");
			f.setParam("carOrderConfId",carOrderConfId);
		}
		List<CarOrderConfDetail> list=find(f);
		if(list==null||list.size()<=0){
			return null;
		}return list.get(0);
	}
}